// FEP v3.1
// auther:zhigang.li
// date:2024.04.26
// 功能:兼容LINUX/WINDOWS
// 实现冗余/负载均衡的FEP（Front End Processor）前置机功能
// 兼容LINUX/WINDOWS，兼容中文/英文windows环境// online DEBUG 开关 -dbg fepdbg
// 支持负载均衡动态转移// 约定：第0行必须是pmon， 第1行必须是FEP所在的行！
// 支持一定的容错，降低敏感度
// 支持日志分析。
// online DEBUG 开关 -dbg fepdbg
// -- 配置变量 -- ：
约定：第0行必须是pmon， 第1行必须是FEP所在的行！
global const string THIS_HOST = "主机"; // 填写：”主机“， ”备机“。 定义本程序运行的是“主机”还是”备机“，
global const string FEP_PARTNER_HOSTNAME =  "MEP1B";
global const int FEP_PARTNER_PMONPORT = 5000; // 伙伴的PMON端口号
global const int FEP_LOCAL_PMONPORT = 5000; // 本地PMON 的端口号

global const dyn_mapping dmPmonConfig = makeDynMapping(
                                     makeMapping("target", "www.winccoa.top",
                                         "index",  3,
                                         "default", "主机"),
                                     makeMapping("target", "www.winccoa.top",
                                         "index",  4,
                                         "default", "备机")
                                 );

// -- 配置变量 END!! -- ：


#uses "fep_lib"

// 主程序
main()
{

  fepctl();
  DebugN("-dbg fepdbg 开启日志, -dbg none 关闭日志");
  DebugN("pmon必须在第一行，fep.ctl必须运行在第二行！");
  DebugN("FEP已经运行!");

}


/*
附件一、mFEP的结构 e.g.
{
    "localhost": {
        "R-0": {
            "PMON_STATE": 2
        },
        "R-1": {
            "PMON_STATE": 2
        },
        "R-2": {
            "PMON_STATE": 2
        },
        "R-3": {
            "PMON_STATE": 2,
            "INDEX": 3,
            "OS_PING_RETURN": [0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            "TARGET_HOSTNAME": "www.winccoa.top",
            "DEFAULT_IN_FEP": "主机"
        },
        "R-4": {
            "PMON_STATE": 2,
            "INDEX": 4,
            "OS_PING_RETURN": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            "TARGET_HOSTNAME": "www.winccoa.top",
            "DEFAULT_IN_FEP": "备机"
        }
    },
    "remote": {
        "R-0": {
            "PMON_STATE": 2
        },
        "R-1": {
            "PMON_STATE": 0
        },
        "R-2": {
            "PMON_STATE": 0
        },
        "R-3": {
            "PMON_STATE": 0
        },
        "R-4": {
            "PMON_STATE": 0
        }
    }
}

附件二、Windows Ping

      C:\>chcp 437 && ping -w 500 -n 1 192.168.1.1
      Active code page: 437

      Pinging 192.168.1.1 with 32 bytes of data:
      Reply from 192.168.1.1: bytes=32 time=5ms TTL=63

      Ping statistics for 192.168.1.1:
          Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
      Approximate round trip times in milli-seconds:
          Minimum = 5ms, Maximum = 5ms, Average = 5ms


附件三、Linux Ping
root@rp:/# ping -w 1 -c 1 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=63 time=1.35 ms

--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.352/1.352/1.352/0.000 ms

附件四、
LIST:5
WCCOActrl5:2; 8160;0;2024.04.26 15:21:17.728;  1
WCCOActrl5:2; 7544;2;2024.04.26 15:28:35.291;  1
WCCOActrl5:2; 5212;2;2024.04.26 18:15:30.611;  5
WCCOActrl5:2; 7516;0;2024.04.26 16:48:03.732; 25
WCCOActrl5:0;   -1;0;2024.04.26 16:48:03.748; 26
WCCOActrl5:2 MONITOR_MODE 0 0
WCCOActrl5:;

*/
